import signal
import traceback

from django.core.management.commands import runserver
from pyim import server


class Command(runserver.Command):
    def add_arguments(self, parser):
        super(Command, self).add_arguments(parser)

    def handle(self, *args, **options):
        try:
            with open("./pyim.pid", "r") as fp:
                id = fp.read()
            signal.signal(signal.SIGKILL, int(id))
        except Exception:
            traceback.print_exc()
